<?php

class model_newagk_questions extends gdl_components_basemodel 
{

    public function primarykey() {
        return 'id';
    }

    public function tableName() {
        return 'agk_questions';

    }
	
	public function getQuestionIds($typeId=0,$level=0,$sectionId=0,$question_bank=0,$question_ids_arr=[])
	{
		$sql_where = 'isdelete=0 and status=1';

		if($typeId) $sql_where .= " and typeId='".$typeId."'";
		if($level) $sql_where .= " and level='".$level."'";
		if($sectionId) $sql_where .= " and sectionId='".$sectionId."'";
		if($question_bank) $sql_where .= " and qbankId='".$question_bank."'";
		if(!empty($question_ids_arr)){
			$ids=[];
			foreach($question_ids_arr as $v){
				$ids[] = intval($v);
			}
			$sql_where .= " and id not in(".implode(',',$ids).")";
		}
		
		
		$res = $this->select($sql_where,'id')->items;

		foreach($res as $val){
			$result[] = $val['id'];	
		}		
		return $result;
	}
	public function getQuestionIdsNum($typeId=0,$level=0,$sectionId=0,$question_bank=0,$num=5)
	{
		
		if($typeId) $sql_where['typeId'] = $typeId;
		if($level) $sql_where['level'] = $level;
		if($sectionId) $sql_where['sectionId'] = $sectionId;
		if($question_bank) $sql_where['qbankId'] = $question_bank;
		
		$res = $this->select($sql_where,'id','limit 0,'.$num)->items;
		
		return count($res);
	}
	
	
	public function getQuestionsById($ids,$order=null){
        if(empty($ids)) return false;
        if(empty($order)) $order = 'id asc';
		
        return $this->select('id in('.implode(',',$ids).')','', 'order by typeId asc,id desc')->items;
    }

}
